

const validator = require('validator');
const { program, InvalidArgumentError } = require('commander');

function check (value) {
  if (!validator.isInt(value)) {
    throw new InvalidArgumentError('Not an integer number');
  }
  return parseInt(value, 10);
}

program
  .argument('[time]', 'timing', 'string')
  .argument('[numbers]', 'this is a number', check, 6)
  .option('-a, --array <array...>', 'this is array')
  .action(async (time, numbers, options) => {
    await main(time, numbers, options.array);
  })

  program.parseAsync(process.argv)
  .then(() => {
    console.log('DONE');
    process.exit(0);
  })
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });

async function main(time, numbers, array) {
  console.log('time=' + time);
  console.log('numbers=' + numbers);
  console.log('array=' + array);
}

